//
//  ZTVideoTableViewController.m
//  zhibo8
//
//  Created by zzt on 16/11/19.
//  Copyright © 2016年 zzt. All rights reserved.
//

#import "ZTVideoTableViewController.h"
#import "UIBarButtonItem+Item.h"
#import "ZTNBAVideoTableViewController.h"
#import "ZTCareVideoTableViewController.h"
#import "ZTFootVideoTableViewController.h"

@interface ZTVideoTableViewController ()
@property (nonatomic, weak) UISegmentedControl* segment;
@end

@implementation ZTVideoTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.设置导航栏
    [self setupNavigationBar];
    
    //2.添加segment的标题控制器
    [self setupTitleView];
}

#pragma mark - 设置导航栏 
- (void)setupNavigationBar {
    
    //titleView == segmentedController
    NSArray *array = [NSArray arrayWithObjects:@"NBA视频",@"关注视频", @"足球视频", nil];
    UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];
    segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
    _segment =segmentedController;
    
    _segment.selectedSegmentIndex = 0;
    //默认选中第0个按钮
    if (_segment.selectedSegmentIndex == 0){
        [self titleClick:_segment];//默认先点击一下,保证ZTBeseSegmentViewController中先滚动时,_segment不为零
    }
    
    [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = segmentedController;
    
    //right
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"搜索0"] selImage:[UIImage imageNamed:@"搜索0"] target:self action:@selector(search)];
}

#pragma mark - segmented点击事件
- (void)segmentAction:(UISegmentedControl* )segment {
    
    [self titleClick:segment];
}

#pragma mark - 搜索框的点击
- (void)search {
    NSLog(@"你点击了搜索框");
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了搜索框" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alter show];
}

#pragma mark - 添加标题view
- (void)setupTitleView {
    
    // NBA视频
    ZTNBAVideoTableViewController *nbaVideo = [[ZTNBAVideoTableViewController alloc]init];
    [self addChildViewController:nbaVideo];
    
    // 关注视频
    ZTCareVideoTableViewController *careVideo = [[ZTCareVideoTableViewController alloc]init];
    [self addChildViewController:careVideo];
    
    // 足球视频
    ZTFootVideoTableViewController *footVideo = [[ZTFootVideoTableViewController alloc]init];
    [self addChildViewController:footVideo];
}

@end
